<template>
  <div class="perfect-one">
    <div class="per-header">
      <p class="per-remind">
        <i class="el-icon-message-solid"></i>提醒：请完善个人资料 ，选择证件类型并上传图片后点击下一步查看并补全基本信息
      </p>
    </div>
    <div class="per-content">
      <div class="per-tab">
        <span>当前位置：</span>
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item to="/">首页</el-breadcrumb-item>
          <el-breadcrumb-item>基本信息</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <div class="per-layer">
        <div class="per-steps">
          <el-steps :active="0" align-center>
            <el-step title="步骤1" description="上传相关证件"></el-step>
            <el-step title="步骤2" description="审核补全个人信息"></el-step>
          </el-steps>
        </div>
        <div class="per-input">
          <el-form ref="form" :model="form" label-width="165px" :rules="rules">
            <el-form-item label="选择需要上传的证件：" prop="value">
              <el-select class="question" v-model="form.value" placeholder="选择上传证件类型">
                <el-option label="身份证" value="身份证"></el-option>
                <el-option label="营业执照" value="营业执照"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="点击上传证件：" required>
              <!-- <el-button type="primary" @click="explain = true">选择图片</el-button> -->
              <Upload @pictures="pictures"></Upload>
            </el-form-item>
            <el-form-item class="item-button">
              <el-button type="primary" :loading="awaiting" @click="submitForm('form')">下一步</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Upload from "@/components/Upload/Upload";
export default {
  data() {
    return {
      form: {
        value: "",
        file: [],
        //储存图片的返回的数据
        imgintro: {},
      },
      rules: {
        value: [
          { required: true, message: "请选择上传证件", trigger: "change" },
        ],
        file: [
          { required: true, message: "请上传你的证件", trigger: "change" },
        ],
      },
      //按钮是否等待
      awaiting: false,
    };
  },
  components: { Upload },
  methods: {
    //上传图片
    pictures(file, fileList) {
      this.form.file = [file.raw];
    },
    //提交
    submitForm(formName) {
      if (this.form.file.length === 0)
        return this.$message.error("请上传你的证件");
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.awaiting = true;
          let formData = new FormData();
          for (var i = 0; i < this.form.file.length; i++) {
            formData.append("file", this.form.file[i]);
          }
          let config = {
            header: {
              "Content-Type": "multipart/form-data",
            },
          };
          if (this.form.value == "身份证") {
            this.$http
              .post("/trademark/distinguish/identityCard", formData, config)
              .then((res) => {
                this.awaiting = false;
                if (res.data.code !== 200) 
                  return ;
                  console.log(res.data.data.path)
                this.form.imgintro = res.data.data;
                this.$router.push({
                  path: "/business/allBusiness/perfectTwo",
                  query: {
                    accountInfo: JSON.stringify(this.form),
                    imgAddr: res.data.data.path,
                  },
                });
              })
              .catch((error) => {
                this.awaiting = false;
              });
          } else {
            this.$http
              .post("/trademark/distinguish/businessLicense", formData, config)
              .then((res) => {
                this.awaiting = false;
                if (res.data.code !== 200)
                  return;
                this.form.imgintro = res.data.data;
                this.$router.push({
                  path: "/business/allBusiness/perfectTwo",
                  query: {
                    accountInfo: JSON.stringify(this.form),
                    imgAddr: res.data.data.path,
                  },
                });
              })
              .catch((error) => {
                this.awaiting = false;
              });
          }
         
        } else {
          return false;
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.perfect-one {
  height: 100%;
  background-color: #f7f7f7;
  .per-header {
    width: 100%;
    height: 50px;
    color: #ff6633;
    background-color: #ffefea;
    line-height: 50px;
    border-radius: 8px;
    margin-bottom: 22px;
    .el-icon-message-solid {
      font-size: 20px;
      padding: 0 5px 0 20px;
    }
  }
  .per-content {
    height: 91%;
    background-color: #fff;
    .per-tab {
      display: flex;
      align-items: center;
      font-size: 16px;
      color: #666666;
      padding: 28px 0 28px 20px;
      border-bottom: 1px solid #eee;
      /deep/.el-icon-arrow-right,
      /deep/.el-breadcrumb__inner {
        font-size: 16px;
        line-height: normal;
      }
    }
    .per-layer {
      margin: 39px 0 0 310px;
      padding-bottom: 20px;
      .per-steps {
        width: 600px;
        margin-bottom: 40px;
      }
      .item-button {
        margin-top: 250px;
      }
    }
    .el-steps {
    width: 90%;
    height: 100px;
      /deep/ .el-step.is-horizontal{
        .is-process{
          border-color: #f96900;
          color: #f96900;
        }
        .is-finish {
          border-color: #333;
          color: #333;
          .el-step__line{
            border-bottom: 1px dashed #333;
            /deep/.el-step__line-inner{
              border-top: 1px dashed #333;
              height: 1px;
              border-bottom: none;
            }
          }
        }
        .el-step__line{
          height: 1px;
          border-bottom: 1px dashed #d9d9d9;
          background: transparent;
          /deep/.el-step__line-inner{
            background: transparent;
            border-style: dashed;
            height: 1px;
            border-bottom: none;
          }
        }
        .el-step__icon.is-text{
          border:1px solid;
          .el-step__icon-inner{
            font-weight: normal;
          }
        }
      }
    }
  }
}
</style>
